from selenium.webdriver.common.by import By
from base.base_action import BaseAction


# 学习项目页面
class LearningProjectPage(BaseAction):

    # 培训管理按钮
    train_manage_btn = By.XPATH, "//span[text()='培训管理']"

    # 培训组织按钮
    train_organization_btn = By.XPATH, ""

    # 学习项目按钮
    learn_project_btn = By.XPATH, "//span[text()='学习项目']"

    # 关键字搜索框
    keyword_search = By.XPATH, "//input[@placeholder='搜索项目']"

    # 时间筛选框
    time_filter = By.XPATH, "//input[@placeholder='开始日期']"

    # 最近一周,最近一个月筛选按钮
    last_week_btn = By.XPATH, "/html/body/div[2]/div[1]/div[1]/button[1]"
    last_month_btn = By.XPATH, "/html/body/div[2]/div[1]/div[1]/button[2]"

    # 状态筛选框
    status_filter = By.XPATH, "//input[@placeholder='状态']"
    have_in_hand_btn = By.XPATH, "/html/body/div[2]/div[1]/div[1]/ul/li[4]/span"
    finished_btn = By.XPATH, "/html/body/div[2]/div[1]/div[1]/ul/li[3]/span"

    # 新建按钮
    new_btn = By.XPATH, "//span[text()='新增项目']"

    # 项目名称输入框
    project_name_input = By.XPATH, "//input[@placeholder='请输入项目名称']"

    # 项目分类输入框
    project_sort_input = By.XPATH, "//input[@placeholder='请选择培训分类']"

    # 选择三级分类
    d1 = By.XPATH, "/html/body/div[2]/div[1]/div[1]/div[1]/ul/li[1]/label/span[1]/span"

    # 空白区域
    blank_area = By.XPATH, "//div[1]/div/div[3]/div[3]/div/div[2]/main/div/div/div[1]/ul"

    # 开始时间输入框
    start_time_input = By.XPATH, "//label[text()='开始时间']/following::div[1]//input"

    # 选择开始时间
    select_start_time = By.XPATH, "//table[@class='el-date-table']/tbody/child::tr[2]/td[1]"

    # 结束时间输入框
    end_time_input = By.XPATH, "//label[text()='结束时间']/following::div[1]//input"

    # 点击下个月
    next_month = By.XPATH, "//div[4]/div[1]/div/div[1]/button[4]"

    # 选择结束时间
    select_end_time = By.XPATH, "//div[4]/div[1]/div/div[2]/table[1]/tbody/tr[5]/td[1]/div/span"

    # 下一步按钮
    next_btn = By.XPATH, "//span[contains(text(),'下一步')]"

    # 新增阶段按钮
    new_stage_btn = By.XPATH, "//div[contains(text(),'+ 新增阶段')]"

    # 阶段名称输入框
    stage_name_input = By.XPATH, "//input[@placeholder='请输入阶段名称']"

    # 确定按钮
    determine_btn = "document.getElementsByClassName('el-button el-button--primary')[0].click();"

    # 面授课程按钮
    face_to_face_btn = By.XPATH, "//span[contains(text(), '面授课程')]"

    # 课程名称输入框
    course_name = By.XPATH, "//input[@placeholder='请选择课程']"

    # 选择课程
    select_course = "document.getElementsByClassName('el-radio__inner')[0].click();"

    # 确定按钮
    determine1_btn = By.XPATH, "/html/body/div[2]/div/div[3]/div/button[1]/span"

    # 小节名称输入框
    content_name_input = By.XPATH, "//div[1]/div/div[3]/div[3]/div/div[2]/main/div/div/div[2]/div[5]/" \
                                   "div/div[2]/div/div/div/div[2]/div[2]/div/div[2]/div[1]/form/div/div/div/input"

    # 选择日期
    select_date = By.XPATH, "//input[@placeholder='选择日期']"
    select_date1 = By.XPATH, "//button[@aria-label='下个月']"
    select_date2 = By.XPATH, "//div[4]/div[1]/div/div[2]/table[1]/tbody/tr[3]/td[1]/div/span"

    # 开始时间输入框
    start_time_input1 = By.XPATH, "//input[@placeholder='开始时间']"

    # 选择开始时间
    select_start_time1 = By.XPATH, "/html/body/div[5]/div[1]/div[1]/div/div[29]"

    # 结束时间输入框
    end_time_input1 = By.XPATH, "//input[@placeholder='结束时间']"

    # 选择结束时间
    select_end_time1 = By.XPATH, "/html/body/div[6]/div[1]/div[1]/div/div[33]"

    # 确定按钮
    determine2_btn = By.XPATH, "//div[1]/div/div[3]/div[3]//div[2]/main//div[2]/div[5]/div/div[3]/div/button[1]/span"

    # 下一步按钮
    next1_btn = By.XPATH, "//span[text()='下一步']"

    # 添加用户按钮
    add_user_btn = By.XPATH, "//span[contains(text(), '添加用户')]"

    # 选择用户复选框
    select_user = "document.getElementsByClassName('el-checkbox__inner')[2].click();"

    # 确定按钮
    determine9_btn = By.XPATH, "//div[2]/div/div[3]/div/button[1]/span"

    # 下一步按钮
    next2_btn = By.XPATH, "//span[text()='下一步']"

    # 选修任务输入框
    elective_input = By.XPATH, "//input[@placeholder='请输入']"

    # 保存并发布按钮
    save_and_publish = By.XPATH, "//span[contains(text(), '保存并发布')]"

    # 点击培训管理按钮
    def click_train_manage_btn(self):
        return self.click(self.train_manage_btn)

    # 点击培训组织
    def click_train_organization_btn(self):
        return self.click(self.train_organization_btn)

    # 点击学习项目按钮
    def click_learn_project_btn(self):
        return self.click(self.learn_project_btn)

    # 输入项目名称进行搜索
    def input_keyword_search(self, content):
        return self.input(self.keyword_search, content)

    # 点击时间筛选框
    def click_time_filter(self):
        return self.click(self.time_filter)

    # 点击最近一周
    def click_last_week_btn(self):
        return self.click(self.last_week_btn)

    # 点击最近一个月
    def click_last_month_btn(self):
        return self.click(self.last_month_btn)

    # 点击状态进行筛选
    def click_status_filter(self):
        return self.click(self.status_filter)

    # 点击进行中
    def click_have_in_hand_btn(self):
        return self.click(self.have_in_hand_btn)

    # 点击已结束
    def click_finished_btn(self):
        return self.click(self.finished_btn)

    # 点击创建按钮
    def click_new_btn(self):
        return self.click(self.new_btn)

    # 输入项目名称
    def input_project_name(self, content):
        return self.input(self.project_name_input, content)

    # 点击项目分类输入框
    def click_project_sort_input(self):
        return self.click(self.project_sort_input)

    # 选择三级分类
    def select_third_sort(self):
        self.click(self.d1)
        return self.click(self.blank_area)

    # 点击开始时间输入框
    def click_start_time_input(self):
        return self.click(self.start_time_input)

    # 选择开始时间
    def click_select_start_time(self):
        return self.click(self.select_start_time)

    # 点击结束时间输入框
    def click_end_time_input(self):
        return self.click(self.end_time_input)

    # 选择结束时间
    def click_select_end_time(self):
        self.click(self.next_month)
        return self.click(self.select_end_time)

    # 点击下一步
    def click_next_btn(self):
        return self.click(self.next_btn)

    # 点击新增阶段按钮
    def click_new_stage_btn(self):
        return self.click(self.new_stage_btn)

    # 输入阶段名称
    def input_stage_name(self, content):
        return self.input(self.stage_name_input, content)

    # 点击确定按钮
    def click_determine_btn(self):
        return self.execute_js(self.determine_btn)

    # 点击面授课程
    def click_face_to_face_btn(self):
        return self.click(self.face_to_face_btn)

    # 点击课程名称
    def click_course_name(self):
        return self.click(self.course_name)

    # 选择课程
    def click_select_course(self):
        return self.execute_js(self.select_course)

    # 点击确定按钮
    def click_determine1_btn(self):
        return self.click(self.determine1_btn)

    # 输入内容名称
    def input_content_name_input(self, content):
        return self.input(self.content_name_input, content)

    # 选择日期
    def click_select_date(self):
        self.click(self.select_date)
        self.click(self.select_date1)
        self.click(self.select_date2)

    # 点击开始时间输入框
    def click_start_time_input1(self):
        return self.click(self.start_time_input1)

    # 选择开始时间
    def click_select_start_time1(self):
        return self.click(self.select_start_time1)

    # 点击结束时间输入框
    def click_end_time_input1(self):
        return self.click(self.end_time_input1)

    # 选择结束时间
    def click_select_end_time1(self):
        return self.click(self.select_end_time1)

    # 点击确定按钮
    def click_confirm(self):
        return self.click(self.determine2_btn)

    # 下一步
    def click_next_step(self):
        return self.click(self.next1_btn)

    # 点击添加用户按钮
    def click_add_user_btn(self):
        return self.click(self.add_user_btn)

    # 选择用户复选框
    def click_select_user(self):
        return self.execute_js(self.select_user)

    # 点击确定按钮
    def click_determine9_btn(self):
        return self.click(self.determine9_btn)

    # 点击下一步按钮
    def click_next2_btn(self):
        return self.click(self.next2_btn)

    # 输入选修任务数量
    def input_elective(self, content):
        return self.input(self.elective_input, content)

    # 点击保存并发布
    def click_save_and_publish(self):
        return self.click(self.save_and_publish)
